﻿Imports TextBoxPrj
Imports TextBoxPrj.TextBoxEx
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Xml
Imports ExternalResource.IconPackage
Imports System.Text
Public Class frmMain
#Region "私有变量"
    ''' <summary>
    ''' 文件名称
    ''' </summary>
    ''' <remarks></remarks>
    Private Filename As String
    ''' <summary>
    ''' 保存文件所使用的编码
    ''' </summary>
    ''' <remarks></remarks>
    Private FileEncoding As Encoding
    ''' <summary>
    ''' 打印文档
    ''' </summary>
    ''' <remarks></remarks>
    Private mPrintDoc As New Printing.PrintDocument
    ''' <summary>
    ''' 第一个显示托盘
    ''' </summary>
    ''' <remarks></remarks>
    Private ToolStripStatusLabelFirst As New ToolStripLabel
    ''' <summary>
    ''' 第二个显示托盘
    ''' </summary>
    ''' <remarks></remarks>
    Private ToolStripStatusLabelSecond As New ToolStripLabel
    Private strRow As String
    Private strCol As String
    Private strCh As String
#End Region
#Region "初始化"
    ''' <summary>
    ''' 构造器
    ''' </summary>
    ''' <remarks></remarks>
    Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        Me.Text = Application_Name
        '从命令行获得参数
        Dim strArgs() As String = System.Environment.GetCommandLineArgs()
        '如果参数长度大于1的话，将第二个参数作为文件名使用
        If strArgs.Length > 1 Then
            If IO.File.Exists(strArgs(1)) Then
                Filename = strArgs(1)
            End If
        End If
        Dim ConfigFileName As String = Application.StartupPath & "\Config.xml"
        If IO.File.Exists(ConfigFileName) Then
            Try
                DefaultConfig = ReadObjectFromXMLFile(GetType(Config), ConfigFileName)
            Catch ex As Exception
                InitConfig()
            End Try
        Else
            InitConfig()
        End If
        Dim mWelcome As New frmWelcome
        mWelcome.ShowDialog()
    End Sub

    ''' <summary>
    ''' 运用设定
    ''' </summary>
    ''' <remarks></remarks>
    Sub UseConfig()
        '读入语言配置文件
        LanguageDoc.Load(Application.StartupPath & "\Language\" & DefaultConfig.MultiLanguage & ".xml")
        '设定表示文字
        strRow = GetTextInLanguageDoc("Row", TextMode.Text) & "："
        strCol = GetTextInLanguageDoc("Column", TextMode.Text) & "："
        strCh = GetTextInLanguageDoc("Ch", TextMode.Text) & "："
        InitMenuAndToolBarText()
        Me.ToolStripStatusLabelFirst.Text = strRow & CodeEditor.InputPosition.Y & Space(4) & _
                                     strCol & CodeEditor.CharPosition & Space(4) & _
                                     strCh & CodeEditor.InputPosition.X
        Me.ToolStripStatusLabelSecond.Text = GetTextInLanguageDoc(CodeEditor.InputMode.ToString, TextMode.Text)
        '编码
        Select Case DefaultConfig.CurrentEncoding
            Case EnumEncoding.ANSI
                SetFileEncoding(ANSIEncoding, Nothing)
            Case EnumEncoding.GB2312
                SetFileEncoding(GB2312Encoding, Nothing)
            Case EnumEncoding.ShfitJIS
                SetFileEncoding(ShfitJISEncoding, Nothing)
            Case EnumEncoding.UTF8
                SetFileEncoding(UTF8Encoding, Nothing)
        End Select
        'SpaceForTab
        Me.CodeEditor.SpaceForTab = DefaultConfig.SpaceForTab
        If DefaultConfig.DefaultCodeConfig <> String.Empty Then
            If IO.File.Exists(Application.StartupPath & "\CodeConfig\" & DefaultConfig.DefaultCodeConfig & ".Xml") Then
                '这里强制刷新语法高亮
                LoadConfig(DefaultConfig.DefaultCodeConfig, Nothing)
            End If
        End If
        'DateTimeFormat
        If DefaultConfig.DateFormat = String.Empty Then DefaultConfig.DateFormat = "yyyy-MM-dd"
        If DefaultConfig.TimeFormat = String.Empty Then DefaultConfig.TimeFormat = "HH:mm:ss"
        '测试DateFormat是否合格
        Try
            Dim TestDateFormat As String = Format(Now, DefaultConfig.DateFormat)
        Catch ex As Exception
            DefaultConfig.DateFormat = "yyyy-MM-dd"
        End Try
        '测试TimeFormat是否合格
        Try
            Dim TestTimeFormat As String = Format(Now, DefaultConfig.TimeFormat)
        Catch ex As Exception
            DefaultConfig.TimeFormat = "HH:mm:ss"
        End Try
    End Sub
    ''' <summary>
    ''' 初始化Config
    ''' </summary>
    ''' <remarks></remarks>
    Sub InitConfig()
        DefaultConfig = New Config
        With DefaultConfig
            .MultiLanguage = "Chinese"
            .CurrentEncoding = EnumEncoding.ANSI
            .SpaceForTab = 4
            .DateFormat = "yyyy-MM-dd"
            .TimeFormat = "HH:mm:ss"
        End With
        WriteObjectToXMLFile(DefaultConfig, GetType(Config), Application.StartupPath & "\Config.xml")
    End Sub
    ''' <summary>
    ''' 窗体关闭
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub SampleTest_FormClosing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.FormClosing
        If CodeEditor.MainDocument.StepList.UndoStepLength + CodeEditor.MainDocument.StepList.RedoStepLength > 0 Then
            Select Case MsgBox(GetTextInLanguageDoc("SaveFile", TextMode.Text), MsgBoxStyle.Question & MsgBoxStyle.YesNoCancel)
                Case MsgBoxResult.Yes
                    File_Save()
                Case MsgBoxResult.Cancel
                    Exit Sub
            End Select
        End If
        WriteObjectToXMLFile(DefaultConfig, GetType(Config), Application.StartupPath & "\Config.xml")
    End Sub
    ''' <summary>
    ''' Load方法
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub SampleTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

        '允许拖放
        Me.AllowDrop = True
        '初始化控件状态
        Me.EditorStatusStrip.Items.Add(ToolStripStatusLabelFirst)
        Me.EditorStatusStrip.Items.Add(ToolStripStatusLabelSecond)
        Me.View_WordWrap_MenuItem.Checked = False
        Me.View_ColumnMode_MenuItem.Checked = False
        '设定右键菜单
        Me.CodeEditor.ContextMenuStrip = Me.EditorContextMenu
        '初始化菜单和工具栏
        InitMenuAndToolBar()
        '获取关键字配置文件列表
        For Each mFile As String In IO.Directory.GetFiles(Application.StartupPath & "\CodeConfig")
            Dim LanguageMenuItem As New System.Windows.Forms.ToolStripMenuItem(mFile.Replace(Application.StartupPath & "\CodeConfig\", "").Replace(".xml", ""))
            Me.Tool_Syntax_MenuItem.DropDownItems.Add(LanguageMenuItem)
            AddHandler LanguageMenuItem.Click, AddressOf LoadConfig
        Next
        '运用设定
        UseConfig()
        Me.ToolStripStatusLabelSecond.Text = GetTextInLanguageDoc(TextBoxPrj.mdlEditor.EnumInputMode.InsertChar.ToString, TextMode.Text)
        '窗体标题
        Me.Text = GetTextInLanguageDoc("NewFile", TextMode.Text) & " - " & Application_Name
        '如果有从命令行传递过来的文件名参数，则打开文件
        If Filename <> String.Empty Then
            CodeEditor.LoadFile(Filename, FileEncoding)
            InitMenuAfterNewOrOpenFile()
            Me.Text = Filename & " - " & Application_Name
            DefaultConfig.AddRecentFiles(Filename)
            ResetRecentFile()
        End If
    End Sub
#End Region
#Region "处理CodeEditor的事件"
    ''' <summary>
    ''' 文件拖曳打开
    ''' </summary>
    ''' <param name="FirstFileName"></param>
    ''' <remarks></remarks>
    Private Sub CodeEditor_DropFile(ByVal FirstFileName As String) Handles CodeEditor.DropFile
        If CodeEditor.MainDocument.StepList.UndoStepLength + CodeEditor.MainDocument.StepList.RedoStepLength > 0 Then
            Select Case MsgBox(GetTextInLanguageDoc("SaveFile", TextMode.Text), MsgBoxStyle.Question & MsgBoxStyle.YesNoCancel)
                Case MsgBoxResult.Yes
                    File_Save()
                Case MsgBoxResult.No
                    '什么也不做。。。。
                Case MsgBoxResult.Cancel
                    Exit Sub
            End Select
        End If
        Me.Filename = FirstFileName
        CodeEditor.LoadFile(Filename, FileEncoding)
        InitMenuAfterNewOrOpenFile()
        Me.Text = Filename & " - " & Application_Name
        DefaultConfig.AddRecentFiles(Filename)
        ResetRecentFile()
    End Sub
    ''' <summary>
    ''' 插入点变动
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ChangePos() Handles CodeEditor.PositionChanged
        Me.ToolStripStatusLabelFirst.Text = strRow & CodeEditor.InputPosition.Y & Space(4) & _
                                     strCol & CodeEditor.CharPosition & Space(4) & _
                                     strCh & CodeEditor.InputPosition.X
        Me.EditorStatusStrip.Refresh()
    End Sub
    ''' <summary>
    ''' 编辑模式变动
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InputModeChanged() Handles CodeEditor.InputModeChanged
        Me.ToolStripStatusLabelSecond.Text = GetTextInLanguageDoc(CodeEditor.InputMode.ToString, TextMode.Text)
    End Sub
    ''' <summary>
    ''' 关键字没有找到
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub RaiseWordNotFound() Handles CodeEditor.WordNotFound
        MsgBox(GetTextInLanguageDoc("WordNotFound", TextMode.Text), MsgBoxStyle.Information)
    End Sub
#End Region
#Region "菜单项-定义"
    '文件
    Dim WithEvents File_MenuItem As New ToolStripMenuItem
    '文件-新建
    Dim WithEvents File_New_MenuItem As New ToolStripMenuItem
    '文件-打开
    Dim WithEvents File_Open_MenuItem As New ToolStripMenuItem
    '文件-保存
    Dim WithEvents File_Save_MenuItem As New ToolStripMenuItem
    '文件-另存为
    Dim WithEvents File_SaveAs_MenuItem As New ToolStripMenuItem
    '文件-编码
    Dim WithEvents File_FileEncoding_MenuItem As New ToolStripMenuItem

    '操作系统默认
    Dim WithEvents ANSIEncoding As New ToolStripMenuItem("ANSI")
    '中国语
    Dim WithEvents GB2312Encoding As New ToolStripMenuItem("GB2312")
    '日本语
    Dim WithEvents ShfitJISEncoding As New ToolStripMenuItem("ShfitJIS")
    'UTF8
    Dim WithEvents UTF8Encoding As New ToolStripMenuItem("UTF8")


    '文件-页面设置
    Dim WithEvents File_PageSetup_MenuItem As New ToolStripMenuItem
    '文件-打印预览
    Dim WithEvents File_PrintPreview_MenuItem As New ToolStripMenuItem
    '文件-打印
    Dim WithEvents File_Print_MenuItem As New ToolStripMenuItem

    '文件-最近文件
    Dim WithEvents File_RecentFiles_MenuItem As New ToolStripMenuItem
    '文件-清除最近文件
    Dim WithEvents File_ClearRecentFiles_MenuItem As New ToolStripMenuItem

    '文件-退出
    Dim WithEvents File_Exit_MenuItem As New ToolStripMenuItem
    '编辑
    Dim WithEvents Edit_MenuItem As New ToolStripMenuItem
    '编辑-撤销
    Dim WithEvents Edit_Undo_MenuItem As New ToolStripMenuItem
    '编辑-重做
    Dim WithEvents Edit_Redo_MenuItem As New ToolStripMenuItem
    '编辑-剪切
    Dim WithEvents Edit_Cut_MenuItem As New ToolStripMenuItem
    '编辑-复制
    Dim WithEvents Edit_Copy_MenuItem As New ToolStripMenuItem
    '编辑-粘贴
    Dim WithEvents Edit_Paste_MenuItem As New ToolStripMenuItem
    '编辑-删除
    Dim WithEvents Edit_Delete_MenuItem As New ToolStripMenuItem
    '编辑-全选
    Dim WithEvents Edit_SelectAll_MenuItem As New ToolStripMenuItem
    '编辑-矩形选择
    Dim WithEvents Edit_BoxSelect_MenuItem As New ToolStripMenuItem
    '编辑-插入
    Dim WithEvents Edit_Insert_MenuItem As New ToolStripMenuItem
    '编辑-插入-时间
    Dim WithEvents Edit_Insert_Time_MenuItem As New ToolStripMenuItem
    '编辑-插入-日期
    Dim WithEvents Edit_Insert_Date_MenuItem As New ToolStripMenuItem
    '编辑-只读
    Dim WithEvents Edit_ReadOnly_MenuItem As New ToolStripMenuItem
    '编辑-重新载入
    Dim WithEvents Edit_ReLoad_MenuItem As New ToolStripMenuItem


    '搜索
    Dim WithEvents Search_MenuItem As New ToolStripMenuItem
    '搜索-查找
    Dim WithEvents Search_Find_MenuItem As New ToolStripMenuItem
    '搜索-查找上一个
    Dim WithEvents Search_FindPrevious_MenuItem As New ToolStripMenuItem
    '搜索-查找下一个
    Dim WithEvents Search_FindNext_MenuItem As New ToolStripMenuItem
    '搜索-高亮关键字
    Dim WithEvents Search_HeightLight_MenuItem As New ToolStripMenuItem
    '搜索-跳转
    Dim WithEvents Search_JumpTo_MenuItem As New ToolStripMenuItem
    '搜索-标志书签
    Dim WithEvents Search_ToggleBookMark_MenuItem As New ToolStripMenuItem
    '搜索-上一个书签
    Dim WithEvents Search_PreviousBookMark_MenuItem As New ToolStripMenuItem
    '搜索-下一个书签
    Dim WithEvents Search_NextBookMark_MenuItem As New ToolStripMenuItem
    '搜索-清除所有书签
    Dim WithEvents Search_ClearAllBookMark_MenuItem As New ToolStripMenuItem

    '视图
    Dim WithEvents View_MenuItem As New ToolStripMenuItem
    '工具-折行显示
    Dim WithEvents View_WordWrap_MenuItem As New ToolStripMenuItem
    '工具-列模式
    Dim WithEvents View_ColumnMode_MenuItem As New ToolStripMenuItem
    '编辑-收缩所有代码
    Dim WithEvents View_CollapseAll_MenuItem As New ToolStripMenuItem
    '编辑-展开所有代码
    Dim WithEvents View_ExpandAll_MenuItem As New ToolStripMenuItem

    '工具
    Dim WithEvents Tool_MenuItem As New ToolStripMenuItem
    '工具-转换为HTML
    Dim WithEvents Tool_ConvertToHTML_MenuItem As New ToolStripMenuItem
    '工具-语法
    Dim WithEvents Tool_Syntax_MenuItem As New ToolStripMenuItem
    '工具-语法设定
    Dim WithEvents Tool_SyntaxConfig_MenuItem As New ToolStripMenuItem
    '工具-选项
    Dim WithEvents Tool_Option_MenuItem As New ToolStripMenuItem

    '帮助
    Dim WithEvents Help_MenuItem As New ToolStripMenuItem
    '帮助-用户手册
    Dim WithEvents Help_UserBook_MenuItem As New ToolStripMenuItem
    '帮助-关于
    Dim WithEvents Help_About_MenuItem As New ToolStripMenuItem

#End Region
#Region "工具栏-定义"
    '文件-新建
    Dim WithEvents File_New_StripButton As New ToolStripButton
    '文件-打开
    Dim WithEvents File_Open_StripButton As New ToolStripButton
    '文件-保存
    Dim WithEvents File_Save_StripButton As New ToolStripButton

    '编辑－撤销
    Dim WithEvents Edit_Undo_StripButton As New ToolStripButton
    '编辑－重做
    Dim WithEvents Edit_Redo_StripButton As New ToolStripButton

    '编辑－剪切
    Dim WithEvents Edit_Cut_StripButton As New ToolStripButton
    '编辑－复制
    Dim WithEvents Edit_Copy_StripButton As New ToolStripButton
    '编辑－粘帖
    Dim WithEvents Edit_Paste_StripButton As New ToolStripButton

    '搜索－查找
    Dim WithEvents Search_Find_StripButton As New ToolStripButton
#End Region
#Region "上下文"
    '编辑-撤销
    Dim WithEvents Edit_Undo_ContextMenuItem As New ToolStripMenuItem
    '编辑-重做
    Dim WithEvents Edit_Redo_ContextMenuItem As New ToolStripMenuItem
    '编辑-剪切
    Dim WithEvents Edit_Cut_ContextMenuItem As New ToolStripMenuItem
    '编辑-复制
    Dim WithEvents Edit_Copy_ContextMenuItem As New ToolStripMenuItem
    '编辑-粘贴
    Dim WithEvents Edit_Paste_ContextMenuItem As New ToolStripMenuItem
    '编辑-删除
    Dim WithEvents Edit_Delete_ContextMenuItem As New ToolStripMenuItem
#End Region
#Region "初始化菜单和工具栏"
    ''' <summary>
    ''' 初始化菜单
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InitMenuAndToolBar()

        '文件-新建
        File_New_MenuItem.Image = GetDefaultImage(IconType.NewFile)
        File_MenuItem.DropDownItems.Add(File_New_MenuItem)
        AddHandler File_New_MenuItem.Click, AddressOf File_New

        File_New_StripButton.Image = GetDefaultImage(IconType.NewFile)
        EditorToolStrip.Items.Add(File_New_StripButton)
        AddHandler File_New_StripButton.Click, AddressOf File_New

        '文件-打开
        File_Open_MenuItem.Image = GetDefaultImage(IconType.OpenFile)
        File_MenuItem.DropDownItems.Add(File_Open_MenuItem)
        AddHandler File_Open_MenuItem.Click, AddressOf File_Open

        File_Open_StripButton.Image = GetDefaultImage(IconType.OpenFile)
        EditorToolStrip.Items.Add(File_Open_StripButton)
        AddHandler File_Open_StripButton.Click, AddressOf File_Open


        '文件-保存
        File_Save_MenuItem.ShowShortcutKeys = True
        File_Save_MenuItem.ShortcutKeys = Keys.Control Or Keys.S
        File_Save_MenuItem.Image = GetDefaultImage(IconType.Save)
        File_MenuItem.DropDownItems.Add(File_Save_MenuItem)
        AddHandler File_Save_MenuItem.Click, AddressOf File_Save

        '文件-另存为
        File_SaveAs_MenuItem.ShowShortcutKeys = True
        File_SaveAs_MenuItem.ShortcutKeys = Keys.Control Or Keys.Shift Or Keys.S
        File_SaveAs_MenuItem.Image = GetDefaultImage(IconType.SaveAs)
        File_MenuItem.DropDownItems.Add(File_SaveAs_MenuItem)
        AddHandler File_SaveAs_MenuItem.Click, AddressOf File_SaveAs


        File_Save_StripButton.Image = GetDefaultImage(IconType.Save)
        EditorToolStrip.Items.Add(File_Save_StripButton)
        AddHandler File_Save_StripButton.Click, AddressOf File_Save

        '文件-编码
        File_MenuItem.DropDownItems.Add(File_FileEncoding_MenuItem)

        '编码列表
        ANSIEncoding.Tag = Encoding.Default
        ANSIEncoding.Checked = True
        ANSIEncoding.CheckOnClick = True
        FileEncoding = Encoding.Default
        File_FileEncoding_MenuItem.DropDownItems.Add(ANSIEncoding)
        AddHandler ANSIEncoding.Click, AddressOf SetFileEncoding

        GB2312Encoding.Tag = Encoding.GetEncoding(936)
        GB2312Encoding.Checked = False
        GB2312Encoding.CheckOnClick = True
        File_FileEncoding_MenuItem.DropDownItems.Add(GB2312Encoding)
        AddHandler GB2312Encoding.Click, AddressOf SetFileEncoding

        ShfitJISEncoding.Tag = Encoding.GetEncoding(932)
        ShfitJISEncoding.Checked = False
        ShfitJISEncoding.CheckOnClick = True
        File_FileEncoding_MenuItem.DropDownItems.Add(ShfitJISEncoding)
        AddHandler ShfitJISEncoding.Click, AddressOf SetFileEncoding

        UTF8Encoding.Tag = Encoding.UTF8
        UTF8Encoding.Checked = False
        UTF8Encoding.CheckOnClick = True
        File_FileEncoding_MenuItem.DropDownItems.Add(UTF8Encoding)
        AddHandler UTF8Encoding.Click, AddressOf SetFileEncoding

        '分割
        File_MenuItem.DropDownItems.Add("-")

        '文件-页面设置
        File_PageSetup_MenuItem.Image = GetDefaultImage(IconType.PageSetup)
        File_MenuItem.DropDownItems.Add(File_PageSetup_MenuItem)
        AddHandler File_PageSetup_MenuItem.Click, AddressOf File_PageSetup

        '文件-打印预览
        File_PrintPreview_MenuItem.Image = GetDefaultImage(IconType.PrintPreview)
        File_MenuItem.DropDownItems.Add(File_PrintPreview_MenuItem)
        AddHandler File_PrintPreview_MenuItem.Click, AddressOf File_PrintPreview

        '文件-打印
        File_Print_MenuItem.Image = GetDefaultImage(IconType.Print)
        File_MenuItem.DropDownItems.Add(File_Print_MenuItem)
        AddHandler File_Print_MenuItem.Click, AddressOf File_Print

        '分割
        File_MenuItem.DropDownItems.Add("-")

        '文件-最近打开文档
        File_MenuItem.DropDownItems.Add(File_RecentFiles_MenuItem)
        ResetRecentFile()

        '文件-清除最近打开文档
        File_MenuItem.DropDownItems.Add(File_ClearRecentFiles_MenuItem)
        AddHandler File_ClearRecentFiles_MenuItem.Click, AddressOf File_ClearRecentFiles

        '分割
        File_MenuItem.DropDownItems.Add("-")

        '文件-退出
        File_Exit_MenuItem.Image = GetDefaultImage(IconType.ExitApp)
        File_MenuItem.DropDownItems.Add(File_Exit_MenuItem)
        AddHandler File_Exit_MenuItem.Click, AddressOf File_Exit
        '文件
        Me.EditorMainMenuStrip.Items.Add(File_MenuItem)

        '分割
        EditorToolStrip.Items.Add(New ToolStripSeparator)

        '编辑-撤销
        Edit_Undo_MenuItem.ShowShortcutKeys = True
        Edit_Undo_MenuItem.ShortcutKeys = Keys.Control Or Keys.Z
        Edit_Undo_MenuItem.Image = GetDefaultImage(IconType.Undo)
        Edit_Undo_MenuItem.Enabled = False
        Edit_MenuItem.DropDownItems.Add(Edit_Undo_MenuItem)
        AddHandler Edit_Undo_MenuItem.Click, AddressOf Edit_Undo

        Edit_Undo_ContextMenuItem.ShowShortcutKeys = True
        Edit_Undo_ContextMenuItem.ShortcutKeys = Keys.Control Or Keys.Z
        Edit_Undo_ContextMenuItem.Image = GetDefaultImage(IconType.Undo)
        Edit_Undo_ContextMenuItem.Enabled = False
        EditorContextMenu.Items.Add(Edit_Undo_ContextMenuItem)
        AddHandler Edit_Undo_ContextMenuItem.Click, AddressOf Edit_Undo

        Edit_Undo_StripButton.Image = GetDefaultImage(IconType.Undo)
        Edit_Undo_StripButton.Enabled = False
        EditorToolStrip.Items.Add(Edit_Undo_StripButton)
        AddHandler Edit_Undo_StripButton.Click, AddressOf Edit_Undo

        '编辑-重做
        Edit_Redo_MenuItem.ShowShortcutKeys = True
        Edit_Redo_MenuItem.ShortcutKeys = Keys.Control Or Keys.Y
        Edit_Redo_MenuItem.Image = GetDefaultImage(IconType.Redo)
        Edit_Redo_MenuItem.Enabled = False
        Edit_MenuItem.DropDownItems.Add(Edit_Redo_MenuItem)
        AddHandler Edit_Redo_MenuItem.Click, AddressOf Edit_Redo

        Edit_Redo_ContextMenuItem.ShowShortcutKeys = True
        Edit_Redo_ContextMenuItem.ShortcutKeys = Keys.Control Or Keys.Y
        Edit_Redo_ContextMenuItem.Image = GetDefaultImage(IconType.Redo)
        Edit_Redo_ContextMenuItem.Enabled = False
        EditorContextMenu.Items.Add(Edit_Redo_ContextMenuItem)
        AddHandler Edit_Redo_ContextMenuItem.Click, AddressOf Edit_Redo

        Edit_Redo_StripButton.Image = GetDefaultImage(IconType.Redo)
        Edit_Redo_StripButton.Enabled = False
        EditorToolStrip.Items.Add(Edit_Redo_StripButton)
        AddHandler Edit_Redo_StripButton.Click, AddressOf Edit_Redo

        '分割
        Edit_MenuItem.DropDownItems.Add("-")
        EditorContextMenu.Items.Add(New ToolStripSeparator)
        EditorToolStrip.Items.Add(New ToolStripSeparator)

        '编辑-剪切
        Edit_Cut_MenuItem.ShowShortcutKeys = True
        Edit_Cut_MenuItem.ShortcutKeys = Keys.Control Or Keys.X
        Edit_Cut_MenuItem.Image = GetDefaultImage(IconType.Cut)
        Edit_MenuItem.DropDownItems.Add(Edit_Cut_MenuItem)
        AddHandler Edit_Cut_MenuItem.Click, AddressOf CodeEditor.Cut

        Edit_Cut_ContextMenuItem.ShowShortcutKeys = True
        Edit_Cut_ContextMenuItem.ShortcutKeys = Keys.Control Or Keys.X
        Edit_Cut_ContextMenuItem.Image = GetDefaultImage(IconType.Cut)
        EditorContextMenu.Items.Add(Edit_Cut_ContextMenuItem)
        AddHandler Edit_Cut_ContextMenuItem.Click, AddressOf CodeEditor.Cut

        Edit_Cut_StripButton.Image = GetDefaultImage(IconType.Cut)
        EditorToolStrip.Items.Add(Edit_Cut_StripButton)
        AddHandler Edit_Cut_StripButton.Click, AddressOf CodeEditor.Cut

        '编辑-复制
        Edit_Copy_MenuItem.ShowShortcutKeys = True
        Edit_Copy_MenuItem.ShortcutKeys = Keys.Control Or Keys.C
        Edit_Copy_MenuItem.Image = GetDefaultImage(IconType.Copy)
        Edit_MenuItem.DropDownItems.Add(Edit_Copy_MenuItem)
        AddHandler Edit_Copy_MenuItem.Click, AddressOf CodeEditor.Copy

        Edit_Copy_ContextMenuItem.ShowShortcutKeys = True
        Edit_Copy_ContextMenuItem.ShortcutKeys = Keys.Control Or Keys.C
        Edit_Copy_ContextMenuItem.Image = GetDefaultImage(IconType.Copy)
        EditorContextMenu.Items.Add(Edit_Copy_ContextMenuItem)
        AddHandler Edit_Copy_ContextMenuItem.Click, AddressOf CodeEditor.Copy

        Edit_Copy_StripButton.Image = GetDefaultImage(IconType.Copy)
        EditorToolStrip.Items.Add(Edit_Copy_StripButton)
        AddHandler Edit_Copy_StripButton.Click, AddressOf CodeEditor.Copy


        '编辑-粘贴
        Edit_Paste_MenuItem.ShowShortcutKeys = True
        Edit_Paste_MenuItem.ShortcutKeys = Keys.Control Or Keys.V
        Edit_Paste_MenuItem.Image = GetDefaultImage(IconType.Paste)
        Edit_MenuItem.DropDownItems.Add(Edit_Paste_MenuItem)
        AddHandler Edit_Paste_MenuItem.Click, AddressOf CodeEditor.Paste

        Edit_Paste_ContextMenuItem.ShowShortcutKeys = True
        Edit_Paste_ContextMenuItem.ShortcutKeys = Keys.Control Or Keys.V
        Edit_Paste_ContextMenuItem.Image = GetDefaultImage(IconType.Paste)
        EditorContextMenu.Items.Add(Edit_Paste_ContextMenuItem)
        AddHandler Edit_Paste_ContextMenuItem.Click, AddressOf CodeEditor.Paste

        Edit_Paste_StripButton.Image = GetDefaultImage(IconType.Paste)
        EditorToolStrip.Items.Add(Edit_Paste_StripButton)
        AddHandler Edit_Paste_StripButton.Click, AddressOf CodeEditor.Paste

        '编辑-删除
        Edit_Delete_MenuItem.ShowShortcutKeys = True
        Edit_Delete_MenuItem.ShortcutKeys = Keys.Delete
        Edit_Delete_MenuItem.Image = GetDefaultImage(IconType.Delete)
        Edit_MenuItem.DropDownItems.Add(Edit_Delete_MenuItem)
        AddHandler Edit_Delete_MenuItem.Click, AddressOf CodeEditor.Delete

        Edit_Delete_ContextMenuItem.ShowShortcutKeys = True
        Edit_Delete_ContextMenuItem.ShortcutKeys = Keys.Delete
        Edit_Delete_ContextMenuItem.Image = GetDefaultImage(IconType.Delete)
        EditorContextMenu.Items.Add(Edit_Delete_ContextMenuItem)
        AddHandler Edit_Delete_ContextMenuItem.Click, AddressOf CodeEditor.Delete


        '分割
        Edit_MenuItem.DropDownItems.Add("-")

        '编辑-插入
        Edit_Insert_MenuItem.Image = GetDefaultImage(IconType.Insert)
        Edit_MenuItem.DropDownItems.Add(Edit_Insert_MenuItem)

        '编辑-插入-时间
        Edit_Insert_Time_MenuItem.ShowShortcutKeys = True
        Edit_Insert_Time_MenuItem.ShortcutKeyDisplayString = "Ctrl + " & Chr(39)
        Edit_Insert_Time_MenuItem.ShortcutKeys = Keys.Control Or Keys.OemQuotes
        Edit_Insert_Time_MenuItem.Image = GetDefaultImage(IconType.Clock)
        Edit_Insert_MenuItem.DropDownItems.Add(Edit_Insert_Time_MenuItem)
        AddHandler Edit_Insert_Time_MenuItem.Click, AddressOf Edit_Insert_Time

        '编辑-插入-日期
        Edit_Insert_Date_MenuItem.ShowShortcutKeys = True
        Edit_Insert_Date_MenuItem.ShortcutKeyDisplayString = "Ctrl + ;"
        Edit_Insert_Date_MenuItem.ShortcutKeys = Keys.Control Or Keys.OemSemicolon
        Edit_Insert_Date_MenuItem.Image = GetDefaultImage(IconType.calendar)
        Edit_Insert_MenuItem.DropDownItems.Add(Edit_Insert_Date_MenuItem)
        AddHandler Edit_Insert_Date_MenuItem.Click, AddressOf Edit_Insert_Date

        '分割
        Edit_MenuItem.DropDownItems.Add("-")

        '编辑-全选
        Edit_SelectAll_MenuItem.ShowShortcutKeys = True
        Edit_SelectAll_MenuItem.ShortcutKeys = Keys.Control Or Keys.A
        Edit_SelectAll_MenuItem.Image = GetDefaultImage(IconType.SelectALL)
        Edit_MenuItem.DropDownItems.Add(Edit_SelectAll_MenuItem)
        AddHandler Edit_SelectAll_MenuItem.Click, AddressOf CodeEditor.SelectAll

        '编辑-矩形选择模式
        Edit_MenuItem.DropDownItems.Add(Edit_BoxSelect_MenuItem)
        AddHandler Edit_BoxSelect_MenuItem.Click, AddressOf Edit_BoxSelect

        '编辑-只读
        Edit_ReadOnly_MenuItem.Image = GetDefaultImage(IconType.Lock)
        Edit_MenuItem.DropDownItems.Add(Edit_ReadOnly_MenuItem)
        AddHandler Edit_ReadOnly_MenuItem.Click, AddressOf Edit_ReadOnly

        '编辑-重载
        Edit_ReLoad_MenuItem.ShortcutKeys = Keys.F5
        Edit_ReLoad_MenuItem.ShowShortcutKeys = True
        Edit_MenuItem.DropDownItems.Add(Edit_ReLoad_MenuItem)
        AddHandler Edit_ReLoad_MenuItem.Click, AddressOf Edit_ReLoad

        '编辑
        Me.EditorMainMenuStrip.Items.Add(Edit_MenuItem)

        '分割
        EditorToolStrip.Items.Add(New ToolStripSeparator)

        '搜索-查找
        Search_Find_MenuItem.ShowShortcutKeys = True
        Search_Find_MenuItem.ShortcutKeys = Keys.Control Or Keys.F
        Search_Find_MenuItem.Image = GetDefaultImage(IconType.Search)
        Search_MenuItem.DropDownItems.Add(Search_Find_MenuItem)
        AddHandler Search_Find_MenuItem.Click, AddressOf Search_Find

        Search_Find_StripButton.Image = GetDefaultImage(IconType.Search)
        EditorToolStrip.Items.Add(Search_Find_StripButton)
        AddHandler Search_Find_StripButton.Click, AddressOf Search_Find


        '搜索-查找上一个
        Search_FindPrevious_MenuItem.ShowShortcutKeys = True
        Search_FindPrevious_MenuItem.ShortcutKeys = Keys.Shift Or Keys.F3
        Search_FindPrevious_MenuItem.Image = GetDefaultImage(IconType.Search_Previous)
        Search_MenuItem.DropDownItems.Add(Search_FindPrevious_MenuItem)
        AddHandler Search_FindPrevious_MenuItem.Click, AddressOf CodeEditor.FindPrevious

        '搜索-查找下一个
        Search_FindNext_MenuItem.ShowShortcutKeys = True
        Search_FindNext_MenuItem.ShortcutKeys = Keys.F3
        Search_FindNext_MenuItem.Image = GetDefaultImage(IconType.Search_Next)
        Search_MenuItem.DropDownItems.Add(Search_FindNext_MenuItem)
        AddHandler Search_FindNext_MenuItem.Click, AddressOf CodeEditor.FindNext

        '搜索-高亮关键字
        Search_HeightLight_MenuItem.Image = GetDefaultImage(IconType.HeightLight)
        Search_MenuItem.DropDownItems.Add(Search_HeightLight_MenuItem)
        AddHandler Search_HeightLight_MenuItem.Click, AddressOf Search_HeightLight

        '搜索-跳转
        Search_JumpTo_MenuItem.ShowShortcutKeys = True
        Search_JumpTo_MenuItem.ShortcutKeys = Keys.Control Or Keys.J
        Search_JumpTo_MenuItem.Image = GetDefaultImage(IconType.JumpTo)
        Search_MenuItem.DropDownItems.Add(Search_JumpTo_MenuItem)
        AddHandler Search_JumpTo_MenuItem.Click, AddressOf Search_JumpTo

        '分割
        Search_MenuItem.DropDownItems.Add(New ToolStripSeparator)

        '搜索-设置书签
        Search_ToggleBookMark_MenuItem.ShortcutKeys = Keys.Control Or Keys.F2
        Search_ToggleBookMark_MenuItem.ShowShortcutKeys = True
        Search_ToggleBookMark_MenuItem.Image = GetDefaultImage(IconType.Flag)
        Search_MenuItem.DropDownItems.Add(Search_ToggleBookMark_MenuItem)
        AddHandler Search_ToggleBookMark_MenuItem.Click, AddressOf Search_ToggleBookMark

        '搜索-上一个书签
        Search_PreviousBookMark_MenuItem.ShortcutKeys = Keys.Shift Or Keys.F2
        Search_PreviousBookMark_MenuItem.ShowShortcutKeys = True
        Search_PreviousBookMark_MenuItem.Image = GetDefaultImage(IconType.Flag_Previous)
        Search_PreviousBookMark_MenuItem.Enabled = False
        Search_MenuItem.DropDownItems.Add(Search_PreviousBookMark_MenuItem)
        AddHandler Search_PreviousBookMark_MenuItem.Click, AddressOf CodeEditor.PreviousBookMark

        '搜索-下一个书签
        Search_NextBookMark_MenuItem.ShortcutKeys = Keys.F2
        Search_NextBookMark_MenuItem.ShowShortcutKeys = True
        Search_NextBookMark_MenuItem.Image = GetDefaultImage(IconType.Flag_Next)
        Search_NextBookMark_MenuItem.Enabled = False
        Search_MenuItem.DropDownItems.Add(Search_NextBookMark_MenuItem)
        AddHandler Search_NextBookMark_MenuItem.Click, AddressOf CodeEditor.NextBookMark

        '搜索-清除置书签
        Search_ClearAllBookMark_MenuItem.Image = GetDefaultImage(IconType.Flag_Delete)
        Search_ClearAllBookMark_MenuItem.Enabled = False
        Search_MenuItem.DropDownItems.Add(Search_ClearAllBookMark_MenuItem)
        AddHandler Search_ClearAllBookMark_MenuItem.Click, AddressOf CodeEditor.ClearBookMark

        '搜索
        Me.EditorMainMenuStrip.Items.Add(Search_MenuItem)

        '视图-收缩代码    
        View_MenuItem.DropDownItems.Add(View_CollapseAll_MenuItem)
        AddHandler View_CollapseAll_MenuItem.Click, AddressOf CodeEditor.CollapseALL

        '视图-展开代码    
        View_MenuItem.DropDownItems.Add(View_ExpandAll_MenuItem)
        AddHandler View_ExpandAll_MenuItem.Click, AddressOf CodeEditor.ExpandAll

        '分割
        View_MenuItem.DropDownItems.Add("-")

        '视图-折行显示
        View_WordWrap_MenuItem.Image = ExternalResource.IconPackage.GetDefaultImage(IconType.WordWrap)
        View_MenuItem.DropDownItems.Add(View_WordWrap_MenuItem)
        AddHandler View_WordWrap_MenuItem.Click, AddressOf View_SwitchWordWrap

        '视图-列模式
        View_MenuItem.DropDownItems.Add(View_ColumnMode_MenuItem)
        AddHandler View_ColumnMode_MenuItem.Click, AddressOf View_ColumnMode

        '视图
        Me.EditorMainMenuStrip.Items.Add(View_MenuItem)

        '工具-转换为HTML
        Tool_ConvertToHTML_MenuItem.Image = GetDefaultImage(IconType.SaveAsHTML)
        Tool_MenuItem.DropDownItems.Add(Tool_ConvertToHTML_MenuItem)
        AddHandler Tool_ConvertToHTML_MenuItem.Click, AddressOf Tool_Convert2HTML

        '分割
        Tool_MenuItem.DropDownItems.Add("-")

        '工具-语法
        Tool_Syntax_MenuItem.Image = ExternalResource.IconPackage.GetDefaultImage(IconType.SyntaxHeightLight)
        Tool_MenuItem.DropDownItems.Add(Tool_Syntax_MenuItem)

        '工具-语法设定
        Tool_SyntaxConfig_MenuItem.Image = ExternalResource.IconPackage.GetDefaultImage(IconType.Settings)
        Tool_MenuItem.DropDownItems.Add(Tool_SyntaxConfig_MenuItem)
        AddHandler Tool_SyntaxConfig_MenuItem.Click, AddressOf Tool_SyntaxConfig

        '工具-选项
        Tool_Option_MenuItem.Image = ExternalResource.IconPackage.GetDefaultImage(IconType.Options)
        Tool_MenuItem.DropDownItems.Add(Tool_Option_MenuItem)
        AddHandler Tool_Option_MenuItem.Click, AddressOf Tool_Option
        '分割
        Tool_MenuItem.DropDownItems.Add("-")
        LoadPlugIn()
        '高级
        Me.EditorMainMenuStrip.Items.Add(Tool_MenuItem)


        '帮助-用户手册
        Help_UserBook_MenuItem.ShowShortcutKeys = True
        Help_UserBook_MenuItem.ShortcutKeys = Keys.Shift Or Keys.F1
        Help_UserBook_MenuItem.Image = ExternalResource.IconPackage.GetDefaultImage(IconType.Books)
        Help_MenuItem.DropDownItems.Add(Help_UserBook_MenuItem)
        AddHandler Help_UserBook_MenuItem.Click, AddressOf Help_UserBook

        '帮助-关于
        Help_About_MenuItem.ShowShortcutKeys = True
        Help_About_MenuItem.ShortcutKeys = Keys.F1
        Help_MenuItem.DropDownItems.Add(Help_About_MenuItem)
        AddHandler Help_About_MenuItem.Click, AddressOf Help_About

        '帮助
        Me.EditorMainMenuStrip.Items.Add(Help_MenuItem)
    End Sub
    ''' <summary>
    ''' 设定菜单和工具栏文字
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub InitMenuAndToolBarText()
        '文件-新建
        File_New_MenuItem.Text = GetTextInLanguageDoc("New")
        File_New_StripButton.ToolTipText = GetTextInLanguageDoc("New", TextMode.Text)
        '文件-打开
        File_Open_MenuItem.Text = GetTextInLanguageDoc("Open")
        File_Open_StripButton.ToolTipText = GetTextInLanguageDoc("Open", TextMode.Text)
        '文件-保存
        File_Save_MenuItem.Text = GetTextInLanguageDoc("Save")
        File_Save_StripButton.ToolTipText = GetTextInLanguageDoc("Save", TextMode.Text)
        '文件-另存为
        File_SaveAs_MenuItem.Text = GetTextInLanguageDoc("SaveAs")
        '文件-编码
        File_FileEncoding_MenuItem.Text = GetTextInLanguageDoc("Encoding")
        '文件-页面设置
        File_PageSetup_MenuItem.Text = GetTextInLanguageDoc("PageSetup")
        '文件-打印预览
        File_PrintPreview_MenuItem.Text = GetTextInLanguageDoc("PrintPreview")
        '文件-打印
        File_Print_MenuItem.Text = GetTextInLanguageDoc("Print")
        '文件-最近文件
        File_RecentFiles_MenuItem.Text = GetTextInLanguageDoc("RecentFiles")
        '文件-清除最近文件
        File_ClearRecentFiles_MenuItem.Text = GetTextInLanguageDoc("ClearRecentFiles")
        '文件-退出
        File_Exit_MenuItem.Text = GetTextInLanguageDoc("Exit")
        '文件
        File_MenuItem.Text = GetTextInLanguageDoc("File")

        '编辑
        Edit_MenuItem.Text = GetTextInLanguageDoc("Edit")
        '编辑-撤销
        Edit_Undo_MenuItem.Text = GetTextInLanguageDoc("Undo")
        Edit_Undo_ContextMenuItem.Text = GetTextInLanguageDoc("Undo")
        Edit_Undo_StripButton.ToolTipText = GetTextInLanguageDoc("Undo", TextMode.Text)
        '编辑-重做
        Edit_Redo_MenuItem.Text = GetTextInLanguageDoc("Redo")
        Edit_Redo_ContextMenuItem.Text = GetTextInLanguageDoc("Redo")
        Edit_Redo_StripButton.ToolTipText = GetTextInLanguageDoc("Redo", TextMode.Text)
        '编辑-剪切
        Edit_Cut_MenuItem.Text = GetTextInLanguageDoc("Cut")
        Edit_Cut_ContextMenuItem.Text = GetTextInLanguageDoc("Cut")
        Edit_Cut_StripButton.ToolTipText = GetTextInLanguageDoc("Cut", TextMode.Text)
        '编辑-复制
        Edit_Copy_MenuItem.Text = GetTextInLanguageDoc("Copy")
        Edit_Copy_ContextMenuItem.Text = GetTextInLanguageDoc("Copy")
        Edit_Copy_StripButton.ToolTipText = GetTextInLanguageDoc("Copy", TextMode.Text)
        '编辑-粘贴
        Edit_Paste_MenuItem.Text = GetTextInLanguageDoc("Paste")
        Edit_Paste_ContextMenuItem.Text = GetTextInLanguageDoc("Paste")
        Edit_Paste_StripButton.ToolTipText = GetTextInLanguageDoc("Paste", TextMode.Text)
        '编辑-删除
        Edit_Delete_MenuItem.Text = GetTextInLanguageDoc("Delete")
        Edit_Delete_ContextMenuItem.Text = GetTextInLanguageDoc("Delete")
        '编辑-插入
        Edit_Insert_MenuItem.Text = GetTextInLanguageDoc("Insert")
        '编辑-插入-时间
        Edit_Insert_Time_MenuItem.Text = GetTextInLanguageDoc("Time")
        '编辑-插入-日期
        Edit_Insert_Date_MenuItem.Text = GetTextInLanguageDoc("Date")
        '编辑-全选
        Edit_SelectAll_MenuItem.Text = GetTextInLanguageDoc("SelectAll")
        '编辑-箱型选择
        Edit_BoxSelect_MenuItem.Text = GetTextInLanguageDoc("BoxSelect")
        '编辑-只读
        Edit_ReadOnly_MenuItem.Text = GetTextInLanguageDoc("ReadOnly")
        '编辑-重载
        Edit_ReLoad_MenuItem.Text = GetTextInLanguageDoc("ReLoad")

        '搜索
        Search_MenuItem.Text = GetTextInLanguageDoc("Search")
        '搜索-查找
        Search_Find_MenuItem.Text = GetTextInLanguageDoc("Find")
        Search_Find_StripButton.ToolTipText = GetTextInLanguageDoc("Find", TextMode.Text)
        '搜索-查找上一个
        Search_FindPrevious_MenuItem.Text = GetTextInLanguageDoc("FindPrevious")
        '搜索-查找下一个
        Search_FindNext_MenuItem.Text = GetTextInLanguageDoc("FindNext")
        '搜索-高亮关键字
        Search_HeightLight_MenuItem.Text = GetTextInLanguageDoc("HeightLight")
        '搜索-跳转
        Search_JumpTo_MenuItem.Text = GetTextInLanguageDoc("JumpTo")
        '搜索-标记书签
        Search_ToggleBookMark_MenuItem.Text = GetTextInLanguageDoc("ToggleBookMark", TextMode.Text)
        '搜索-上一个书签
        Search_PreviousBookMark_MenuItem.Text = GetTextInLanguageDoc("PreviousBookMark", TextMode.Text)
        '搜索-下一个书签
        Search_NextBookMark_MenuItem.Text = GetTextInLanguageDoc("NextBookMark", TextMode.Text)
        '搜索-清除书签
        Search_ClearAllBookMark_MenuItem.Text = GetTextInLanguageDoc("ClearAllBookMark", TextMode.Text)

        '视图
        View_MenuItem.Text = GetTextInLanguageDoc("View")
        '视图-收缩代码
        View_CollapseAll_MenuItem.Text = GetTextInLanguageDoc("CollapseAll")
        '视图-展开代码
        View_ExpandAll_MenuItem.Text = GetTextInLanguageDoc("ExpandAll")
        '视图-折行显示
        View_WordWrap_MenuItem.Text = GetTextInLanguageDoc("WordWrap")
        '视图-列模式
        View_ColumnMode_MenuItem.Text = GetTextInLanguageDoc("ColumnMode")

        '工具-转换为HTML
        Tool_ConvertToHTML_MenuItem.Text = GetTextInLanguageDoc("ConvertToHTML")
        '工具-语言
        Tool_Syntax_MenuItem.Text = GetTextInLanguageDoc("Syntax")
        '工具-语言设定
        Tool_SyntaxConfig_MenuItem.Text = GetTextInLanguageDoc("SyntaxConfig")
        '工具-选项
        Tool_Option_MenuItem.Text = GetTextInLanguageDoc("Option")
        '工具
        Tool_MenuItem.Text = GetTextInLanguageDoc("Tool")

        '帮助
        Help_MenuItem.Text = GetTextInLanguageDoc("Help")
        '帮助-用户手册
        Help_UserBook_MenuItem.Text = GetTextInLanguageDoc("Userbook")
        '帮助-关于
        Help_About_MenuItem.Text = GetTextInLanguageDoc("About")
    End Sub
#End Region
End Class